# -*- coding: utf-8 -*-

from ..base_client import BaseClient
from common_sdk.system.sys_env import get_env


class CustomerClient(BaseClient):

    resource = "customer"

    def __init__(self):
        super().__init__()
        self.domain = get_env("TRADE_SERVICE_DOMAIN")

    def check_customer(self, builder):
        result = self.do_http_post_only_data(
            self.__generate_uri("check_customer"),
            params=builder.params,
            headers=builder.headers
        )
        return result

    def update_customer(self, builder):
        result = self.do_http_post_only_data(
            self.__generate_uri("update"),
            params=builder.params,
            headers=builder.headers
        )
        return result

    def get_customer(self, builder):
        result = self.do_http_post_only_data(
            self.__generate_uri("get"),
            params={"id": builder.user_id},
            headers=builder.headers
        )
        return result

    # 微信小程序登陆
    def wechat_mini_program_login(self, builder):
        result = self.do_http_post_only_data(
            self.__generate_uri("wechat_mini_program_login"),
            params=builder.params,
            headers=builder.headers
        )
        return result

    def wechat_mini_program_auth(self, builder):
        result = self.do_http_post_only_data(
            self.__generate_uri("wechat_mini_program_auth"),
            params=builder.params,
            headers=builder.headers
        )
        return result

    def __generate_uri(self, operation):
        uri = f"{self.resource}/{operation}"
        return uri
